import { merge } from 'lodash-es'
import { getViewportPx } from '@/utils/formatter'
const fontSize = getViewportPx(14)
// 饼图公共hook
export const usePieOptions = (data: any[], options?: any) => {
  let baseOptions: any = {
    color: [
      '#FC5C53',
      '#47D147',
      '#F5BF49',
      '#5486F0',
      '#C763F2',
      '#3ba272',
      '#fc8452',
      '#9a60b4',
      '#ea7ccc'
    ],
    title: {
      text: '',
      left: 'left',
      padding: [2, 2, 2, 2],
      textStyle: {
        fontSize: getViewportPx(16)
      }
    },
    tooltip: {
      trigger: 'item',
      formatter: '{b} : {c} ({d}%)'
    },
    legend: {
      bottom: getViewportPx(0),
      // itemWidth: 10,
      // itemHeight: 10,
      icon: 'circle',
      textStyle: {
        fontSize: getViewportPx(16)
      }
    },
    series: [
      {
        bottom: getViewportPx(10),
        type: 'pie',
        radius: ['45%', '82%'],
        center: ['50%', '50%'],
        avoidLabelOverlap: false,
        itemStyle: {
          borderRadius: 10,
          borderColor: '#fff',
          borderWidth: 0
        },
        label: {
          show: true,
          color: '#fff',
          position: 'inside',
          formatter: '{d}%',
          fontSize
        },
        minAngle: 20,
        // minShowLabelAngle: 0.001,
        data: [...data]
      }
    ]
  }
  baseOptions = merge(baseOptions, options)
  return {
    baseOptions
  }
}
